package edu.gduf.parcel.service.impl;

import java.util.Date;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import edu.gduf.parcel.common.constant.ParcelConstant;
import edu.gduf.parcel.common.util.DateUtils;
import edu.gduf.parcel.common.vo.Result;
import edu.gduf.parcel.entity.Admin;
import edu.gduf.parcel.repository.AdminMapper;
import edu.gduf.parcel.service.AdminService;
import edu.gduf.parcel.vo.AdminVo;

@Service
public class AdminServiceImpl implements AdminService {
	@Autowired
	private AdminMapper adminMapper;

	@Override
	public Result doLogin(AdminVo adminVo) {
		if (StringUtils.isBlank(adminVo.getUsername()))
			return new Result(ParcelConstant.Result.CODE_ERROR, ParcelConstant.Result.MSG_ACCOUNT_BLANK,
					DateUtils.getCurDateStr());
		if (StringUtils.isBlank(adminVo.getPassword()))
			return new Result(ParcelConstant.Result.CODE_ERROR, ParcelConstant.Result.MSG_PASSWOED_BLANK,
					DateUtils.getCurDateStr());
		Admin admin = adminMapper.selectByAccount(adminVo.getUsername());
		if (admin == null)
			return new Result(ParcelConstant.Result.CODE_ERROR, ParcelConstant.Result.MSG_ACCOUNT_NO_EXIST,
					DateUtils.getCurDateStr());
		if (!adminVo.getPassword().equals(admin.getPassword()))
			return new Result(ParcelConstant.Result.CODE_ERROR, ParcelConstant.Result.MSG_PASSWORD_ERROR,
					DateUtils.getCurDateStr());
		else
			return new Result(ParcelConstant.Result.CODE_SUCESS, ParcelConstant.Result.MSG_SUCCESS,
					DateUtils.getCurDateStr());
	}

}
